package server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.UserInfoBase;

import org.apache.catalina.Session;

public class PageChangeServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out=resp.getWriter();
		out.println("<html><body><h1>This is a servlet test PageChangeServlet . welcome</h1></body></html>");
		
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		
		String page = req.getParameter("page");
		String username = req.getParameter("username");
		PrintWriter out=resp.getWriter();
		out.println("page:"+page);
		out.println("username:"+username);
		UserInfoBase info = (UserInfoBase) req.getSession().getAttribute(username);
		info.page = Integer.parseInt(page);
		req.getRequestDispatcher("main.jsp").forward(req, resp);
	}

}
